package com.sllp.C71S3TsllpShop.biz.impl;


import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.sllp.C71S3TsllpShop.bean.ChartData;
import com.sllp.C71S3TsllpShop.bean.OrdersItem;
import com.sllp.C71S3TsllpShop.bean.OrdersItemExample;
import com.sllp.C71S3TsllpShop.bean.Product;
import com.sllp.C71S3TsllpShop.bean.OrdersItemExample.Criteria;
import com.sllp.C71S3TsllpShop.bean.Specs;
import com.sllp.C71S3TsllpShop.biz.OrdersItemBiz;
import com.sllp.C71S3TsllpShop.dao.OrdersItemMapper;
import com.sllp.C71S3TsllpShop.util.GenerateOrdersItemChartData;

@Service
public class OrdersItemBizImpl implements OrdersItemBiz {

	@Resource
	private OrdersItemMapper oim;
	@Resource
	private GenerateOrdersItemChartData generateOrdersItemChartData;
	
	//确认收货，修改订单详情状态
	public int confirmReceipt(String id){
		OrdersItem ordersitem=new OrdersItem();
		ordersitem.setState(4);
		OrdersItemExample oie=new OrdersItemExample();
		Criteria c=oie.createCriteria();
		c.andIdEqualTo(id);
		int ok=oim.updateByExampleSelective(ordersitem, oie);
		return ok;
	}
	//取消订单
	public int del(String id){
		OrdersItemExample oie=new OrdersItemExample();
		Criteria c=oie.createCriteria();
		c.andIdEqualTo(id);
		OrdersItem ordersItem = new OrdersItem();
		ordersItem.setState(5);
		int ok=oim.updateByExampleSelective(ordersItem, oie);
		return ok;
	}
	
	//添加评论后修改订单状态为8
	public int updateOrderState(String id){
		OrdersItem orderitem=new OrdersItem();
		orderitem.setState(8);
		OrdersItemExample oie=new OrdersItemExample();
		Criteria c=oie.createCriteria();
		c.andIdEqualTo(id);
		int ok=oim.updateByExampleSelective(orderitem, oie);
		return ok;
	}
	//根据订单详情号查商品
	public OrdersItem findpro(String id){
		OrdersItem list=oim.selectByPrimaryKey(id);
		return list;
	}

	@Override
	public int updateOrdersItemState(OrdersItem ordersItem) {
		OrdersItemExample itemExample = new OrdersItemExample();
		itemExample.createCriteria().andIdEqualTo(ordersItem.getId());
		return oim.updateByExampleSelective(ordersItem, itemExample);
	}
	
	@Override
	public List<OrdersItem> selectAll(){
		return oim.selectByExample(null);
	}

	@Override
	public List<ChartData> generateIndexChartData() {
		List<OrdersItem> ordersItems = selectAll();
		return generateOrdersItemChartData.generateOrdersItemChartData(ordersItems);
	}
	
	@Override
	public List<OrdersItem> selectOrdersItem(Product product,BigDecimal prePrice,BigDecimal nextPrice,OrdersItem ordersItem,Integer pageNum,Integer pageSize){
		if(pageNum != null && pageSize != null) {
			PageHelper.startPage(pageNum, pageSize);
			List<OrdersItem> ordersItems = oim.selectByBusiness(product, prePrice, nextPrice, ordersItem);
			
			return ordersItems;
		}
		List<OrdersItem> ordersItems = oim.selectByBusiness(product, prePrice, nextPrice, ordersItem);
		
		return ordersItems;
	}
	
}
